/*
 * @Author: vinton
 * @Date: 2021-07-02 15:16:49
 * @LastEditTime: 2021-09-02 10:15:45
 * @LastEditors: Vinton
 * @Description: In User Settings Edit
 * @FilePath: /dc-cocos-tools/utils/downLoadComp.js
 */
const path = require('path')
const fs = require("fs");
const downloadRepo = require('./downLoad')
const { tplPrefix } = require('../config/index')


/**
 * @description: 下载远程仓库文件夹
 * @param {*}
 * @return {*}
 */
function createLoaclComponents() {
    // const cwd = path.join(process.cwd(), 'demo1')
    // Editor.log(tplPrefix, '开始下载====>', `${path.join(__dirname, '../temp')}`)
    deleteFile(`${path.join(__dirname, '../temp')}`).then(()=>{
        downloadRepo(`${tplPrefix}/dc-vizier-cocos-ui#master`, `${path.join(__dirname, '../temp')}`)
    })
}
/**
 * @description:  删除某个文件夹下面的所有内容
 * @param {*} path 需要删除文件夹路径
 * @return {*}
 */
function deleteFile(path) {
    return new Promise((resolve) => {
        var files = [];
        if (fs.existsSync(path)) {
            files = fs.readdirSync(path);
            files.forEach(function (file, index) {
                var curPath = path + "/" + file;
                if (fs.statSync(curPath).isDirectory()) {
                    deleteFile(curPath);
                } else {
                    fs.unlinkSync(curPath);
                }
            });
            fs.rmdirSync(path);
        }
        return resolve()
    })
};
// createLoaclComponents()
module.exports = {
    createLoaclComponents
}